package cn.scau.server.controller;


import cn.scau.server.pojo.Notification;
import cn.scau.server.service.NotificationService;
import cn.scau.server.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代码不跑我先跑
 * @since 2025-03-30
 */
@RestController
@RequestMapping("/notification")
public class NotificationController {
    @Autowired
    public NotificationService notificationService;

    // 根据消息id查找消息
    @GetMapping("/getMessageById")
    public ResultVO<Notification> getMessageById(Integer id) {
        return notificationService.getMessageById(id);
    }

    //修改未读为已读
    @PostMapping("/markAsRead")
    public ResultVO changeIsReadById(Integer id) {
        return notificationService.changeIsReadById(id);
    }

    //新增消息通知
    @PostMapping("/addNotification")
    public ResultVO addNotification(Notification notification) {
        boolean success = notificationService.save(notification);
        if (success) {
            return ResultVO.success("通知添加成功");
        } else {
            return ResultVO.fail("通知添加失败");
        }
    }

    //根据员工编号查找所有消息
    @GetMapping("/getMessageByEmpId")
    public ResultVO<List<Notification>> getMessageByEmpId(String id) {
        return notificationService.getMessageByEmpId(id);
    }

    // 判断员工是否有未读消息
    @GetMapping("/checkUnreadMessages")
    public ResultVO checkUnreadMessages(String id) {
        return notificationService.checkUnreadMessages(id);
    }

}
